package com.xiaoran.commonapi.config;

import com.xiaoran.commonapi.entity.Properties;
import com.xiaoran.commonapi.entity.Rst;
import com.xiaoran.commonapi.tencent.Sms;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@EnableConfigurationProperties(Properties.class)
public class PropertiesAutoConfiguration {
    private final Properties properties;

    public PropertiesAutoConfiguration(Properties properties) {
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean
    public Sms sms() {
        return new Sms(this.properties.getTencent_sms_per_limit_time()
                , this.properties.getTencent_sms_limit_24_num()
                , this.properties.getTencent_sms_code_save_time());
    }

    @Bean
    @ConditionalOnMissingBean
    public Rst rst() {
        return new Rst(this.properties.getRst_default_error_code()
                , this.properties.getRst_default_success_code()
                , this.properties.getRst_default_success_msg(),
                this.properties.getRst_default_error_msg());
    }
}
